/*-----------------
** 1.[15] Would Algorithm C still work if i varies 
**  from 2 to N in step C2, instead of from N down to 2? 
**  What if j varies from 1 up to i-1 in step C3?
**-----------------
** Auther: coanor
** Date:2009.10.11
*/

#include <stdlib.h>
#include <stdio.h>

#define ARR_SZ 16

int main()
{
  int count[ARR_SZ] = {0};
  int R[ARR_SZ] = {503,87,512,61,908,170,897,275,653,426,154,509,612,677,765,703};
  int i,j;  
 
  /* Excercise 1:
  ** i varies from 2 to N.
  ** At the same time, j varies from 1 up to i
  */
  for (i = 0; i < ARR_SZ - 1; ++i) {
    for (j = i + 1; j <= ARR_SZ - 1; ++j) {
      if (R[i] == R[j]) {			   
        continue; 
      }
      if (R[i] > R[j])
        count[i]++;
      else
        count[j]++;
    }
  }
  for (i = 0; i < ARR_SZ; ++i) {
     printf("%4d ", count[i]+1);
  }
	
  exit(0);
}
